#define _CRT_SECURE_NO_WARNINGS 1

struct Node* copyRandomList(struct Node* head) {
    if (head == NULL)
        return head;
    struct Node* cur = head;
    struct Node* Next = NULL;
    struct Node* copy = NULL;
    while (cur)
    {
        copy = (struct Node*)malloc(sizeof(struct Node));
        Next = cur->next;
        cur->next = copy;
        copy->val = cur->val;
        copy->next = Next;
        // copy->random=cur->random;
        cur = Next;
    }
    cur = head;
    while (cur)
    {
        copy = cur->next;
        if (cur->random == NULL)
        {
            copy->random = NULL;
        }
        else {

            copy->random = cur->random->next;

        }
        cur = cur->next->next;

    }


    cur = head;
    struct Node* poi = cur->next;
    while (cur)
    {
        Next = cur->next->next;
        copy = cur->next;
        if (Next == NULL)
        {
            copy->next = NULL;
        }
        else
        {
            copy->next = Next->next;
        }
        cur = Next;
    }
    return poi;

}
